package cn.edu.scau.cmi.dengshixin.factory;

import java.net.URL;
import java.util.ResourceBundle;

import cn.edu.scau.cmi.dengshixin.factoryProduct.Meat;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;

public class Controller {
	@FXML
    private ResourceBundle resources;

    @FXML
    private URL location;

    @FXML
    private TextField inputField;

    @FXML
    private Button cookButton;

    @FXML
    private Label showLabel;

    @FXML
    void getClicked(ActionEvent event) {
    	String meatName = inputField.getText();
    	inputField.clear();
    	if(meatName.equals("")) return;
    	
    	Factory factory = null;
    	Meat meat;
		switch(meatName) {
		case "Beaf":
			factory = new BeafFactory();
			break;
		case "Chicken":
			factory = new ChickenFactory();
			break;
		case "Pork":
			factory = new PorkFactory();
			break;
		}
		if(factory != null) {
			meat = factory.produce();
			showLabel.setText(meat.cook());
		}
		else
			showLabel.setText("没有生产该种肉类的工厂！");
    }

    @FXML
    void initialize() {
        assert inputField != null : "fx:id=\"inputField\" was not injected: check your FXML file 'SimpleFactoryFX.fxml'.";
        assert cookButton != null : "fx:id=\"cookButton\" was not injected: check your FXML file 'SimpleFactoryFX.fxml'.";
        assert showLabel != null : "fx:id=\"showLabel\" was not injected: check your FXML file 'SimpleFactoryFX.fxml'.";

    }
}
